package com.gs.coursera.algorithms.core.graph;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;



public class UndirectedGraph<T, W extends Comparable<W>> extends Graph<T, W> {

	public UndirectedGraph(int vertexCount) {
		super(vertexCount);
	}


	@Override
	public boolean addVertex(Vertex<T, W> vertex) {
		if(vertex == null)
			return false;
		getVertices().set(vertex.getVertexNumber(), vertex);
		
		return true;
	}
	
	@Override
	public void addEdge(Edge<T, W> edge) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addEdge(T valueOne, T valueTwo, W weight) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addEdge(Vertex<T, W> v1, Vertex<T, W> v2,
			W weight) {
		if(null != v1 && null != v2){
			Edge<T, W> edge = new Edge<T, W>(v1, v2, weight);
			v1.addAdjacentEdge(edge);
			getEdges().add(edge);
			Edge<T, W> edgeRev = new Edge<T, W>(v2, v1, weight);
			v2.addAdjacentEdge(edgeRev);
		}
	}


	@Override
	public List<Vertex<T, W>> getAdjacencyList(Vertex<T, W> v) {
		List<Vertex<T, W>> adj = new ArrayList<Vertex<T,W>>();
		
		for (Vertex<T, W> vertex : getVertices()) {
			if(vertex.equals(v)){
				Set<Edge<T, W>> adjSet = vertex.getAdjacencyList();
				for (Edge<T, W> edge : adjSet) {
					adj.add(edge.getEndVertex());
				}
			}
		}
		
		return adj;
	}

	
}
